#include<bits/stdc++.h>
using namespace std;
const int N=100005;

int n,m;
char c[N];
int fath[N][20][3];
vector<int> edges[N];
bool visit[N];
int lg[N],h[N];

void dfs(int fa,int son){
	visit[fa]=true;visit[son]=true;
	h[son]=h[fa]+1;
	fath[son][0][0]=fa;
	fath[son][0][1]=(c[fa]=='H'||c[son]=='H'?1:0);
	fath[son][0][2]=(c[fa]=='G'||c[son]=='G'?1:0);
	for(int i=1;i<=lg[h[son]-1];i++){
		fath[son][i][0]=fath[fath[son][i-1][0]][i-1][0];
		fath[son][i][1]=fath[son][i-1][1]||fath[fath[son][i-1][0]][i-1][1];
		fath[son][i][2]=fath[son][i-1][2]||fath[fath[son][i-1][0]][i-1][2];
	}
	for(auto u:edges[son]){
		if(!visit[u]){
			dfs(son,u);
		}
	}
}
int match(int x,int y,int w){
	if(h[x]<h[y]) swap(x,y);
	while(h[x]>h[y]){
		int st=lg[h[x]-h[y]];
		if(fath[x][st][w]) return 1;
		x=fath[x][st][0];
	}
	if(x==y){
		if(c[x]=='H'&&w==1) return 1;
		if(c[x]=='G'&&w==2) return 1;
		return 0;
	}
	for(int k=lg[h[x]];k>=0;k--){
		if(fath[x][k][0]!=fath[y][k][0]){
			if(fath[x][k][w]||fath[y][k][w]) return 1;
			x=fath[x][k][0];
			y=fath[y][k][0];
		}
	}
	if(fath[x][0][w]||fath[y][0][w]) return 1;
	return 0;
}

int main(){
	cin>>n>>m;
	string str;
	cin>>str;
	c[0]='Q';
	for(int i=0;str[i]!='\0';i++){
		c[i+1]=str[i];
	}
	int s,t;
	for(int i=1;i<n;i++){
		cin>>s>>t;
		edges[s].emplace_back(t);
		edges[t].emplace_back(s);
	}
	lg[1]=1;
	for(int i=2;i<=n;i++){
		lg[i]=lg[i-1]+(1<<lg[i-1]==i?1:0);
		lg[i-1]--;
	}
	lg[n]--;
	memset(visit,false,sizeof(visit));
	h[0]=0;
	dfs(0,1);
	//
	char ch;
	for(int i=0;i<m;i++){
		cin>>s>>t>>ch;
		if(ch=='H') cout<<match(s,t,1);
		if(ch=='G') cout<<match(s,t,2);
	}
	return 0;
}
